package main.java.dao.impl;

import main.java.dao.AppointmentDao;
import main.java.dao.BaseDAO;
import main.java.polo.Appointment;


import java.util.Collections;
import java.util.List;

public class AppointmentDaoImpl extends BaseDAO implements AppointmentDao {
    @Override
    public List<Appointment> selectByName(String studentName) {
        try {
            String sql = "select id apId ,student_name studentName ,doctor_name doctorName ," +
                    "appointment_time appointmentTime,appointment_status appointmentStatus from appointment where student_name =?";
            return executeQuery(Appointment.class, sql,studentName);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int delete(Integer apId) {
        try {
            String sql = "delete from appointment where id = ?";
            return executeUpdate(sql,apId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int insert(Appointment appointment) {
        try {
            String sql = "insert into appointment (student_name,doctor_name,appointment_time) values (?,?,?)";
            return executeUpdate(sql,appointment.getStudentName(),appointment.getDoctorName(),appointment.getAppointmentTime());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
